package com.ruoyi.collect.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.collect.domain.RecipeCollectionItems;
import com.ruoyi.collect.mapper.RecipeCollectionItemsMapper;
import com.ruoyi.collect.service.IRecipeCollectionItemsService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 菜谱收藏关系Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-08-13
 */
@Service
public class RecipeCollectionItemsServiceImpl implements IRecipeCollectionItemsService
{
    @Autowired
    private RecipeCollectionItemsMapper recipeCollectionItemsMapper;

    /**
     * 查询菜谱收藏关系
     * 
     * @param id 菜谱收藏关系主键
     * @return 菜谱收藏关系
     */
    @Override
    public RecipeCollectionItems selectRecipeCollectionItemsById(String id)
    {
        return recipeCollectionItemsMapper.selectRecipeCollectionItemsById(id);
    }

    /**
     * 查询菜谱收藏关系列表
     * 
     * @param recipeCollectionItems 菜谱收藏关系
     * @return 菜谱收藏关系
     */
    @Override
    public List<RecipeCollectionItems> selectRecipeCollectionItemsList(RecipeCollectionItems recipeCollectionItems)
    {
        return recipeCollectionItemsMapper.selectRecipeCollectionItemsList(recipeCollectionItems);
    }

    /**
     * 新增菜谱收藏关系
     * 
     * @param recipeCollectionItems 菜谱收藏关系
     * @return 结果
     */
    @Override
    public int insertRecipeCollectionItems(RecipeCollectionItems recipeCollectionItems)
    {
        recipeCollectionItems.setCreateTime(DateUtils.getNowDate());
        return recipeCollectionItemsMapper.insertRecipeCollectionItems(recipeCollectionItems);
    }

    /**
     * 修改菜谱收藏关系
     * 
     * @param recipeCollectionItems 菜谱收藏关系
     * @return 结果
     */
    @Override
    public int updateRecipeCollectionItems(RecipeCollectionItems recipeCollectionItems)
    {
        return recipeCollectionItemsMapper.updateRecipeCollectionItems(recipeCollectionItems);
    }

    /**
     * 批量删除菜谱收藏关系
     * 
     * @param ids 需要删除的菜谱收藏关系主键
     * @return 结果
     */
    @Override
    public int deleteRecipeCollectionItemsByIds(String[] ids)
    {
        return recipeCollectionItemsMapper.deleteRecipeCollectionItemsByIds(ids);
    }

    /**
     * 删除菜谱收藏关系信息
     * 
     * @param id 菜谱收藏关系主键
     * @return 结果
     */
    @Override
    public int deleteRecipeCollectionItemsById(String id)
    {
        return recipeCollectionItemsMapper.deleteRecipeCollectionItemsById(id);
    }


    @Override
    public RecipeCollectionItems findById(String id) {
        return recipeCollectionItemsMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, RecipeCollectionItems recipeCollectionItems) {
        PageHelper.startPage(pageNum,pageSize);
        List<RecipeCollectionItems> list = recipeCollectionItemsMapper.select(recipeCollectionItems);
        PageInfo<RecipeCollectionItems> pageInfo = new PageInfo<>(list);
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put("total", pageInfo.getTotal());
        pageMap.put("pages", pageInfo.getPages());
        pageMap.put("list", pageInfo.getList());
        return pageMap;
    }

    @Override
    public List<RecipeCollectionItems> findAllCollections() {
        return recipeCollectionItemsMapper.select(null);
    }

    @Override
    public int remove(Integer id) {
        return recipeCollectionItemsMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return recipeCollectionItemsMapper.deleteBatch(ids);
    }

    @Override
    public int add(RecipeCollectionItems recipeCollectionItems) {
        return recipeCollectionItemsMapper.insert(recipeCollectionItems);
    }


}
